<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <canvas id="canvasId" width="400" height="400"></canvas>
  <script type="text/javascript">
  var canvas = document.getElementById("canvasId");
  var ctx = canvas.getContext("2d");
  var img = new Image();
  img.src = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3538853800,3766799738&fm=27&gp=0.jpg";
  img.onload = function (){
      ctx.save();//保存状态
      ctx.translate(200,200);//设置画布上的(0,0)位置，也就是旋转的中心点
      ctx.rotate(45*Math.PI/180);
      ctx.drawImage(img,-img.width/2,-img.height/2);//把图片绘制在旋转的中心点，
      ctx.restore();//恢复状态
  }
  </script>
</body>
</html>
